from django.shortcuts import render
from django.views.generic import DetailView, ListView
from .models import Album, AlbumImage


# Create your views here.
class AlbumListView(ListView):
    queryset = Album.objects.filter(is_visible=True).order_by('-create_date')
    paginate_by = 1


class AlbumDetail(DetailView):
    model = Album

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super().get_context_data(**kwargs)
        # Add in a QuerySet of all the images
        context['image'] = AlbumImage.objects.filter(album=self.object.id)
        return context
